module DynamicScaffoldResourceTestHelper # :nodoc:
  def test_included
    assert true
  end
  
  def test_should_get_index
    get :index
    assert_response :success
    assert assigns(@singular_name.pluralize)
  end
  
  def test_should_get_new
    get :new
    assert_response :success
  end  

  def test_should_get_show
    get :show, :id => 1
    assert_response :success
  end

  def test_should_get_edit
    get :edit, :id => 1
    assert_response :success
  end

  def test_should_create_resource
    resource_class = eval(@singular_name.camelize)
    old_count = resource_class.count
    post :create, @singular_name.to_sym => { }
    assert_equal old_count+1, resource_class.count
 
    assert_redirected_to eval("#{@singular_name}_path(assigns(:#{@singular_name}))")
  end

  def test_should_update_resource
    put :update, :id => 1, @singular_name.to_sym => { }
    assert_redirected_to eval("#{@singular_name}_path(assigns(:#{@singular_name}))")
  end
  
  def test_should_destroy_resource
    resource_class = eval(@singular_name.camelize)
    old_count = resource_class.count
    delete :destroy, :id => 1
    assert_equal old_count-1, resource_class.count
    
    assert_redirected_to eval("#{@singular_name.pluralize}_path")
  end
end